package com.appmagna.sleepaidfan;

import android.annotation.TargetApi;
import android.content.Context;
import android.media.AudioAttributes;
import android.media.MediaPlayer;
import android.media.SoundPool;
import android.os.Build;
import android.util.Log;

public class LoopMediaPlayer {
    private static final int MAX_STREAM = 10;
    private static final int PRIORITY = 1;
    private static final int SRC_QUALITY = 0;
    public static final String TAG = LoopMediaPlayer.class.getSimpleName();
    private Context mContext = null;
    private int mCounter = 1;
    private MediaPlayer mCurrentPlayer = null;
    private MediaPlayer mNextPlayer = null;
    private int mResId = 0;
    /* access modifiers changed from: private */
    public SoundPool mSoundPool = null;
    private float mVolume = 0.0f;
    /* access modifiers changed from: private */
    public int sound_id = 0;
    int streamId = 0;

    public static LoopMediaPlayer create(Context context, int resId, float volume) {
        return new LoopMediaPlayer(context, resId, volume);
    }

    public void stopPlay() {
        if (this.mSoundPool != null) {
            this.mSoundPool.stop(this.sound_id);
            this.mSoundPool.release();
        }
    }

    public LoopMediaPlayer(Context context, int resId, final float volume) {
        this.mContext = context;
        this.mResId = resId;
        this.mVolume = volume;
        createSoundPool();
        this.sound_id = this.mSoundPool.load(this.mContext, this.mResId, 1);
        this.mSoundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
            public void onLoadComplete(SoundPool soundPool, int soundID, int status) {
                Log.e(LoopMediaPlayer.TAG, "soundID" + soundID + "    status:" + status);
                Log.e("volume", String.valueOf(volume));
                LoopMediaPlayer.this.streamId = LoopMediaPlayer.this.mSoundPool.play(LoopMediaPlayer.this.sound_id, volume, volume, 1, -1, 1.0f);
            }
        });
    }

    /* access modifiers changed from: protected */
    public void createSoundPool() {
        if (Build.VERSION.SDK_INT >= 21) {
            createNewSoundPool();
        } else {
            createOldSoundPool();
        }
    }

    /* access modifiers changed from: protected */
    @TargetApi(21)
    public void createNewSoundPool() {
        this.mSoundPool = new SoundPool.Builder().setAudioAttributes(new AudioAttributes.Builder().setUsage(1).setContentType(2).build()).build();
    }

    /* access modifiers changed from: protected */
    public void createOldSoundPool() {
        this.mSoundPool = new SoundPool(10, 3, 0);
    }

    public SoundPool getSoundPool() {
        return this.mSoundPool;
    }

    public int getStreamId() {
        return this.streamId;
    }
}
